package com.bfs.anasit.service;

import com.bfs.anasit.model.Patient;
import com.bfs.anasit.repository.PatientRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.inject.Named;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: lukman
 * Date: 6/11/11
 * Time: 8:42 PM
 * To change this template use File | Settings | File Templates.
 */
@Service("patientService")
@Named("patientService")
@SessionScoped
public class PatientServiceImpl implements PatientService {

    @SuppressWarnings("unused")
    @PersistenceContext
    private EntityManager em;

    @Autowired
    private PatientRepository patientRepository;

    @Override
    public Patient findByPatientId(Long patientId) {
        return patientRepository.findByPatientId(patientId);
    }

    @Override
    public List<Patient> findAllPatients() {
        return patientRepository.findAll();
    }

    @Override
    public void update(Patient patient) {

        patientRepository.save(patient);
    }

    @Override
    public void delete(Patient patient) {
        patientRepository.delete(patient);
    }

    @Override
    public void save(Patient patient) {
        patientRepository.save(patient);
    }
}
